﻿@model CustomerInfoModel
@using Nop.Web.Models.Customer;
@using Nop.Core;
@{
    Layout = "~/Views/Shared/_ColumnsOne.cshtml";

    //title
    Html.AddTitleParts(T("PageTitle.Account").Text);
}

@Html.Partial("MyAccountNavigation", Model.NavigationModel, new ViewDataDictionary())

@if (Model.CountryEnabled && Model.StateProvinceEnabled)
{
    <script type="text/javascript">
        $(function () {
            $("#@Html.FieldIdFor(model => model.CountryId)").change(function () {
                var selectedItem = $(this).val();
                var ddlStates = $("#@Html.FieldIdFor(model => model.StateProvinceId)");
             var statesProgress = $("#states-loading-progress");
             statesProgress.show();
             $.ajax({
                 cache: false,
                 type: "GET",
                 url: "@(Url.RouteUrl("GetStatesByCountryId"))",
                    data: { "countryId": selectedItem, "addEmptyStateIfRequired": "true" },
                    success: function (data) {
                        ddlStates.html('');
                        $.each(data, function (id, option) {
                            ddlStates.append($('<option></option>').val(option.id).html(option.name));
                        });
                        statesProgress.hide();
                    },
                    error: function (xhr, ajaxOptions, thrownError) {
                        alert('Failed to retrieve states.');
                        statesProgress.hide();
                    }
                });
            });
        });
    </script>
}
<div class="page account-page customer-info-page">
    <div class="page-title">
        <h1>@T("Account.MyAccount") - @T("Account.CustomerInfo")</h1>
    </div>
    <div class="page-body">
        @using (Html.BeginForm())
        {
            @Html.AntiForgeryToken()
            <div class="message-error">
                @Html.ValidationSummary(true)
            </div>
            <div class="fieldset">
                <div class="title">
                    <strong>@T("Account.YourPersonalDetails")</strong>
                </div>
                <div class="form-fields">
                    @if (Model.GenderEnabled)
                    {
                        <div class="inputs">
                            <label>@T("Account.Fields.Gender"):</label>
                            <span class="gender">
                                @Html.RadioButton("Gender", "M", (Model.Gender == "M"), new { id = "gender-male" })
                                <span class="forcheckbox" for="gender-male">@T("Account.Fields.Gender.Male")</span>
                            </span>
                            <span class="gender">
                                @Html.RadioButton("Gender", "F", (Model.Gender == "F"), new { id = "gender-female" })
                                <span class="forcheckbox" for="gender-female">@T("Account.Fields.Gender.Female")</span>
                            </span>
                        </div>
                    }
                    <div class="inputs">
                        @Html.LabelFor(model => model.FirstName, new { }, ":")
                        @Html.EditorFor(model => model.FirstName)
                        @Html.RequiredHint()
                        @Html.ValidationMessageFor(model => model.FirstName)
                    </div>
                    <div class="inputs">
                        @Html.LabelFor(model => model.LastName, new { }, ":")
                        @Html.EditorFor(model => model.LastName)
                        @Html.RequiredHint()
                        @Html.ValidationMessageFor(model => model.LastName)
                    </div>
                    @if (Model.DateOfBirthEnabled)
                    {
                        <div class="inputs">
                            <label>@T("Account.Fields.DateOfBirth"):</label>
                            @Html.DatePickerDropDowns(Html.FieldNameFor(x => x.DateOfBirthDay),
                                        Html.FieldNameFor(x => x.DateOfBirthMonth),
                                        Html.FieldNameFor(x => x.DateOfBirthYear),
                                        DateTime.Now.Year - 110,
                                        DateTime.Now.Year,
                                        Model.DateOfBirthDay,
                                        Model.DateOfBirthMonth,
                                        Model.DateOfBirthYear)
                            @Html.ValidationMessageFor(model => model.DateOfBirthDay)
                            @Html.ValidationMessageFor(model => model.DateOfBirthMonth)
                            @Html.ValidationMessageFor(model => model.DateOfBirthYear)
                        </div>
                    }
                    <div class="inputs">
                        @Html.LabelFor(model => model.Email, new { }, ":")
                        @Html.EditorFor(model => model.Email)
                        @Html.RequiredHint()
                        @Html.ValidationMessageFor(model => model.Email)
                    </div>
                    @if (Model.UsernamesEnabled)
                    {
                        if (Model.AllowUsersToChangeUsernames)
                        {
                        <div class="inputs">
                            @Html.LabelFor(model => model.Username, new { }, ":")
                            @Html.EditorFor(model => model.Username)
                            @Html.RequiredHint()
                            @Html.ValidationMessageFor(model => model.Username)
                            @if (Model.CheckUsernameAvailabilityEnabled)
                            {
                                @Html.Partial("_CheckUsernameAvailability")
                            }
                        </div>
                        }
                        else
                        {
                        <div class="inputs">
                            @Html.LabelFor(model => model.Username, new { }, ":")
                            @Model.Username
                        </div>
                        }
                    }
                </div>
            </div>    
                    if (Model.AssociatedExternalAuthRecords.Count > 0)
                    {
            <div class="fieldset">
                <div class="title">
                    <strong>@T("Account.AssociatedExternalAuth")</strong>
                </div>
                <table class="data-table">
                    <colgroup>
                        <col />
                        <col />
                        <col />
                    </colgroup>
                    <thead>
                        <tr>
                            <th class="a-center auth-method-name">
                                @T("Account.AssociatedExternalAuth.AuthMethodName")
                            </th>
                            <th class="a-center email">
                                @T("Account.AssociatedExternalAuth.Email")
                            </th>
                            <th class="a-center external-id">
                                @T("Account.AssociatedExternalAuth.ExternalIdentifier")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.AssociatedExternalAuthRecords)
                        {
                            <tr>
                                <td class="a-left auth-method-name">
                                    @item.AuthMethodName
                                </td>
                                <td class="a-left email">
                                    @item.Email
                                </td>
                                <td class="a-left external-id">
                                    @CommonHelper.EnsureMaximumLength(item.ExternalIdentifier, 40, "...")
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
                    }
                    if (Model.CompanyEnabled || Model.DisplayVatNumber)
                    {
            <div class="fieldset">
                <div class="title">
                    <strong>@T("Account.CompanyDetails")</strong>
                </div>
                <div class="form-fields">
                    @if (Model.CompanyEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.Company, new { }, ":")
                            @Html.EditorFor(model => model.Company)
                            @if (Model.CompanyRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.Company)
                        </div>
                    }
                    @if (Model.DisplayVatNumber)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.VatNumber, new { }, ":")
                            @Html.EditorFor(model => model.VatNumber)&nbsp;&nbsp;&nbsp;@Model.VatNumberStatusNote
                            <span class="vat-note"><em>@T("Account.Fields.VatNumber.Note")</em></span>
                        </div>
                    }
                </div>
            </div>
                    }
                    if (Model.StreetAddressEnabled ||
                                Model.StreetAddress2Enabled ||
                                Model.ZipPostalCodeEnabled ||
                                Model.CityEnabled ||
                                Model.CountryEnabled)
                    {
            <div class="fieldset">
                <div class="title">
                    <strong>@T("Account.YourAddress")</strong>
                </div>
                <div class="form-fields">
                    @if (Model.StreetAddressEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.StreetAddress, new { }, ":")
                            @Html.EditorFor(model => model.StreetAddress)
                            @if (Model.StreetAddressRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.StreetAddress)
                        </div>
                    }
                    @if (Model.StreetAddress2Enabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.StreetAddress2, new { }, ":")
                            @Html.EditorFor(model => model.StreetAddress2)
                            @if (Model.StreetAddress2Required)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.StreetAddress2)
                        </div>
                    }
                    @if (Model.ZipPostalCodeEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.ZipPostalCode, new { }, ":")
                            @Html.EditorFor(model => model.ZipPostalCode)
                            @if (Model.ZipPostalCodeRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.ZipPostalCode)
                        </div>
                    }
                    @if (Model.CityEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.City, new { }, ":")
                            @Html.EditorFor(model => model.City)
                            @if (Model.CityRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.City)
                        </div>
                    }
                    @if (Model.CountryEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.CountryId, new { }, ":")
                            @Html.DropDownList("CountryId", Model.AvailableCountries)
                        </div>
                    }
                    @if (Model.CountryEnabled && Model.StateProvinceEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.StateProvinceId, new { }, ":")
                            @Html.DropDownList("StateProvinceId", Model.AvailableStates)
                            <span id="states-loading-progress" style="display: none;" class="please-wait">@T("Common.Wait...")</span>
                        </div>
                    }
                </div>
            </div>            
                    }
                    if (Model.PhoneEnabled || Model.FaxEnabled)
                    {
            <div class="fieldset">
                <div class="title">
                    <strong>@T("Account.YourContactInformation")</strong>
                </div>
                <div class="form-fields">
                    @if (Model.PhoneEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.Phone, new { }, ":")
                            @Html.EditorFor(model => model.Phone)
                            @if (Model.PhoneRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.Phone)
                        </div>
                    }
                    @if (Model.FaxEnabled)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.Fax, new { }, ":")
                            @Html.EditorFor(model => model.Fax)
                            @if (Model.FaxRequired)
                            {
                                @Html.RequiredHint()
                            }
                            @Html.ValidationMessageFor(model => model.Fax)
                        </div>
                    }
                </div>
            </div>
                    }
                    if (Model.NewsletterEnabled)
                    {
            <div class="fieldset">
                <div class="title">
                    <strong>@T("Account.Options")</strong>
                </div>
                <div class="form-fields">
                    <div class="inputs">
                        @Html.LabelFor(model => model.Newsletter, new { }, ":")
                        @Html.EditorFor(model => model.Newsletter)
                        @Html.ValidationMessageFor(model => model.Newsletter)
                    </div>
                </div>
            </div>
                    }
                    if (Model.AllowCustomersToSetTimeZone || Model.SignatureEnabled)
                    { 
            <div class="fieldset">
                <div class="title">
                    <strong>@T("Account.Preferences")</strong>
                </div>
                <div class="form-fields">
                    @if (Model.AllowCustomersToSetTimeZone)
                    {
                        <div class="inputs">
                            @Html.LabelFor(model => model.TimeZoneId, new { }, ":")
                            @Html.DropDownList("TimeZoneId", Model.AvailableTimeZones)
                            @Html.ValidationMessageFor(model => model.TimeZoneId)
                        </div>
                    }
                    @if (Model.SignatureEnabled)
                    {             
                        <div class="inputs">
                            @Html.LabelFor(model => model.Signature, new { }, ":")
                            @Html.TextAreaFor(model => model.Signature, new { @class = "account-signature-text" })
                        </div>
                    }
                </div>
            </div>
                    }
            <div class="buttons">
                <input type="submit" value="@T("Common.Save")" name="save-info-button" class="button-1 save-customer-info-button" />
            </div>
        }
    </div>
</div>
